from fastapi.responses import JSONResponse


class Response:
    def __new__(cls, code=200, message="操作成功", data=None, status=None):
        # 直接返回JSONResponse对象
        return JSONResponse(
            content={
                'code': code,
                'message': message,
                'data': data,
                'status': status or ('success' if code == 200 else 'error')
            },
            status_code=code
        )

    @classmethod
    def success(cls, data=None, message="操作成功", code=200):
        # 直接返回JSONResponse对象
        return JSONResponse(
            content={
                'code': code,
                'message': message,
                'data': data,
                'status': 'success'
            },
            status_code=code
        )

    @classmethod
    def error(cls, code, message="操作失败", data=None):
        # 直接返回JSONResponse对象
        return JSONResponse(
            content={
                'code': code,
                'message': message,
                'data': data,
                'status': 'error'
            },
            status_code=code
        )
